import { usePost, useGet } from 'utils/request.js'

const contentPath = '/auth/oauth'

export const login = (param) => {
  return usePost(`${contentPath}/token?grant_type=mobile_password`, param, {
    header: {
      Authorization: 'Basic ZXhhbXBsZS1tb2JpbGU6ZXhhbXBsZS1tb2JpbGU=',
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

export const refreshToken = (refresh_token) => {
  return usePost(`${contentPath}/token?grant_type=refresh_token`, {refresh_token}, {
    header: {
      Authorization: 'Basic ZXhhbXBsZS1tb2JpbGU6ZXhhbXBsZS1tb2JpbGU=',
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// #ifdef MP-WEIXIN
export const wxLogin = (param) => {
  return usePost(`${contentPath}/token?grant_type=wx_login`, param, {
    header: {
      Authorization: 'Basic ZXhhbXBsZS1tb2JpbGU6ZXhhbXBsZS1tb2JpbGU=',
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}
// #endif

export const checkToken = () => {
  return useGet(`${contentPath}/check_token`)
}

export const logout = () => {
  return usePost(`${contentPath}/logout`)
}
